package main

import (
	"context"
	"fmt"
	"github.com/apache/rocketmq-client-go/v2"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/apache/rocketmq-client-go/v2/producer"
	"time"
)

func main() {
	nameSrv := []string{"10.26.10.175:9876"}
	p, err := rocketmq.NewProducer(
		producer.WithNameServer(nameSrv),
		//producer.WithNsResolver(primitive.NewPassthroughResolver(endPoint)),
		//producer.WithRetry(2),
		producer.WithGroupName("imooc"),
		producer.WithSendMsgTimeout(3*time.Second),
	)
	if err != nil {
		panic("producer 初始化失败")
	}
	err = p.Start()
	if err != nil {
		panic("producer 启动失败")
	}

	err = p.SendOneWay(context.Background(), &primitive.Message{
		Topic: "go_test",
		Body:  []byte("Hello RocketMQ"),
	})
	if err != nil {
		fmt.Println("send message error:", err)
		return
	}
	p.Shutdown()

}
